﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using KimPhongCRM.Models;
using DevExpress.Web.Mvc;

namespace KimPhongCRM.Controllers
{
    [PermissionFilter]
    public class LichSuLuatTinhDiemController : BaseController
    {
        KimPhongCRM.Models.Entities db = new KimPhongCRM.Models.Entities();
        List<KimPhongCRM.Models.sp_Select_Combobox_User_Result> listUser = new List<sp_Select_Combobox_User_Result>();
        //
        // GET: /LichSuLuatTinhDiem/
        public LichSuLuatTinhDiemController()
        {
            listUser = db.sp_Select_Combobox_User().ToList();
        }
        [MvcSiteMapProvider.MvcSiteMapNode(Title = "Lịch sử", Key = "lsLuatTinhDiem", Clickable = true, ParentKey = "LuatTinhDiem")]
        public ViewResult Index()
        {
            ViewData["listUser"] = listUser;
            return View(db.tblLichSuLuatTinhDiems.ToList());
        }

        //
        // GET: /LichSuLuatTinhDiem/Details/5

        public ViewResult Details(long id)
        {
            tblLichSuLuatTinhDiem tbllichsuluattinhdiem = db.tblLichSuLuatTinhDiems.Find(id);
            return View(tbllichsuluattinhdiem);
        }

        //
        // GET: /LichSuLuatTinhDiem/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /LichSuLuatTinhDiem/Create

        [HttpPost]
        public ActionResult Create(tblLichSuLuatTinhDiem tbllichsuluattinhdiem)
        {
            if (ModelState.IsValid)
            {
                db.tblLichSuLuatTinhDiems.Add(tbllichsuluattinhdiem);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(tbllichsuluattinhdiem);
        }

        //
        // GET: /LichSuLuatTinhDiem/Edit/5

        public ActionResult Edit(long id)
        {
            tblLichSuLuatTinhDiem tbllichsuluattinhdiem = db.tblLichSuLuatTinhDiems.Find(id);
            return View(tbllichsuluattinhdiem);
        }

        //
        // POST: /LichSuLuatTinhDiem/Edit/5

        [HttpPost]
        public ActionResult Edit(tblLichSuLuatTinhDiem tbllichsuluattinhdiem)
        {
            if (ModelState.IsValid)
            {
                db.Entry(tbllichsuluattinhdiem).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(tbllichsuluattinhdiem);
        }

        //
        // GET: /LichSuLuatTinhDiem/Delete/5

        public ActionResult Delete(long id)
        {
            tblLichSuLuatTinhDiem tbllichsuluattinhdiem = db.tblLichSuLuatTinhDiems.Find(id);
            return View(tbllichsuluattinhdiem);
        }

        //
        // POST: /LichSuLuatTinhDiem/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(long id)
        {
            tblLichSuLuatTinhDiem tbllichsuluattinhdiem = db.tblLichSuLuatTinhDiems.Find(id);
            db.tblLichSuLuatTinhDiems.Remove(tbllichsuluattinhdiem);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }

        [ValidateInput(false)]
        public ActionResult ListLichSuLuatTinhDiemPartial()
        {
            ViewData["listUser"] = listUser;
            var model = db.tblLichSuLuatTinhDiems;
            return PartialView("_ListLichSuLuatTinhDiemPartial", model.ToList());
        }

        [HttpPost, ValidateInput(false)]
        public ActionResult ListLichSuLuatTinhDiemPartialAddNew(KimPhongCRM.Models.tblLichSuLuatTinhDiem item)
        {
            var model = new object[0];
            if (ModelState.IsValid)
            {
                try
                {
                    // Insert here a code to insert the new item in your model
                }
                catch (Exception e)
                {
                    ViewData["EditError"] = e.Message;
                }
            }
            else
                ViewData["EditError"] = "Please, correct all errors.";
            return PartialView("_ListLichSuLuatTinhDiemPartial", model);
        }
        [HttpPost, ValidateInput(false)]
        public ActionResult ListLichSuLuatTinhDiemPartialUpdate(KimPhongCRM.Models.tblLichSuLuatTinhDiem item)
        {
            var model = new object[0];
            if (ModelState.IsValid)
            {
                try
                {
                    // Insert here a code to update the item in your model
                }
                catch (Exception e)
                {
                    ViewData["EditError"] = e.Message;
                }
            }
            else
                ViewData["EditError"] = "Please, correct all errors.";
            return PartialView("_ListLichSuLuatTinhDiemPartial", model);
        }
        [HttpPost, ValidateInput(false)]
        public ActionResult ListLichSuLuatTinhDiemPartialDelete(System.Int64 maLichSu)
        {
            var model = new object[0];
            if (maLichSu != null)
            {
                try
                {
                    // Insert here a code to delete the item from your model
                }
                catch (Exception e)
                {
                    ViewData["EditError"] = e.Message;
                }
            }
            return PartialView("_ListLichSuLuatTinhDiemPartial", model);
        }
    }
}